package utils;

import com.atguigu.spzx.model.entity.system.SysUser;

import java.util.Date;

public class SysUserThreadLocal {
    private static final ThreadLocal<SysUser> threadLocal = new ThreadLocal<>();
    /*private static final ThreadLocal<Date> threadLocalDate = new ThreadLocal<Date>();

    public static void setDate(){
        threadLocalDate.set(new Date());
    }
    public static Date getDate(){
        return threadLocalDate.get();
    }*/




    public static void setSysUser(SysUser sysUser) {
        //向thread对象的map中，put一组k-v
        //threadLocal作为key
        //sysUser作为value
        threadLocal.set(sysUser);
    }

    public static SysUser getSysUser() {
        //从thread对象的map中，获取key为threadLocal的value
        //threadLocal作为key
        //sysUser作为value
        return threadLocal.get();
    }

    public static void removeSysUser() {
        threadLocal.remove();
    }
}
